//
//  RegistrationViewController.m
//  project
//
//  Created by 黄建华 on 2018/1/8.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "RegistrationViewController.h"
#import <MOBFoundation/MOBFoundation.h>
#import "YJLocalCountryData.h"
#import "SectionsViewController.h"
#import "SNPersonSetViewController.h"
#import "SHESelectTable.h"
#define CODECOUNTVALUE 60
#define KSW  [UIScreen mainScreen].bounds.size.width
#define KSH  [UIScreen mainScreen].bounds.size.height

@interface RegistrationViewController () <UITextFieldDelegate, UITextViewDelegate>

@property (nonatomic, strong) UILabel     *naTitle;
@property (nonatomic, strong) UITextField *textFiled1;
@property (nonatomic, strong) UITextField *textFiled2;
@property (nonatomic, strong) UITextField *textFiled3;
@property (nonatomic, strong) UITextField *textFiled4;
@property (nonatomic, strong) UITextField *requestTextFiled1;
@property (nonatomic, strong) UITextField *requestTextFiled2;
@property (nonatomic, strong) UIButton       *areaButton;
@property (nonatomic, strong) UIButton  *loginButton;
@property (nonatomic, strong) UILabel *requestSelect1;
@property (nonatomic, strong) UILabel *requestSelect2;
@property (nonatomic, assign) NSInteger select1;
@property (nonatomic, assign) NSInteger select2;
@end

@implementation RegistrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = SNCOLORWHITE;
    CGFloat height = FitSimpleIpx(0, 20);
    CGFloat heightSize = FitSimpleSize(-20, 0, 8 ,15, 20);
    CGFloat heightIp4 = FitSimpleSize(10, 0, 0 ,0, 0);
    CGFloat fontSize = FitSimpleSize(-1, 0, 1, 2, 3);

    UIView *StateView = [[UIView alloc] init];
    StateView.frame           = CGRectMake(0, 0, kSCREEN_WIDTH, 20 +height);
    StateView.backgroundColor = BBIGSTATECOLOR;
    [self.view addSubview:StateView];
    
    UIView *naView = [[UIView alloc] init];
    naView.frame           = SNFRAME(0, 20 +height, kSCREEN_WIDTH, 44);
    naView.backgroundColor = WELLGOCOLORWHITE;
    [self.view addSubview:naView];
    naView.layer.shadowColor   = WELLGOCOLORBLACK.CGColor;//shadowColor阴影颜色
    naView.layer.shadowOffset  = CGSizeMake(1, 1);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    naView.layer.shadowOpacity = 0.5;//阴影透明度，默认0
    naView.layer.shadowRadius  = 1;//阴影半径，默认3

    UIImageView *image = [[UIImageView alloc] init];
    image.frame = CGRectMake(5, 20 +height, 44, 44);
    image.image = [UIImage image:@"进入"];
    [self.view addSubview:image];
    
    UIButton *backButton = [[UIButton alloc] init];
    backButton.frame = CGRectMake(0, 20+height, 70, 44);
    [backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    _naTitle               = [[UILabel alloc] initWithFrame:SNFRAME(0, 0, HHHWIDTH, 20)];
    _naTitle.center        = CGPointMake(HHHWIDTH/2, naView.centerY);
    _naTitle.text          = SN_Text(@"注册");
    _naTitle.font          = SNSFONT(17.0);
    _naTitle.textAlignment = NSTextAlignmentCenter;
    _naTitle.textColor     = WELLGOCOLORBLACK;
    [self.view addSubview:_naTitle];
    
    _areaButton       = [[UIButton alloc] init];
    _areaButton.frame = CGRectMake(20, 95, 50, 35);
    
    UIView *view1 = [[UIView alloc] init];
    view1.frame               = CGRectMake(45, 95, kSCREEN_WIDTH - 90, 30);
    view1.backgroundColor     = WELLGOCOLORWHITE;
    view1.alpha               = 0.07;
    view1.layer.cornerRadius  = 18;
    view1.layer.masksToBounds = YES;
    [self.view addSubview:view1];
    
    UIView *view2 = [[UIView alloc] init];
    view2.frame               = CGRectMake(45, view1.y + 30, 130, 30);
    view2.backgroundColor     = WELLGOCOLORWHITE;
    view2.alpha               = 0.07;
    view2.layer.cornerRadius  = 18;
    view2.layer.masksToBounds = YES;
    [self.view addSubview:view2];
    
    UIView *view3 = [[UIView alloc] init];
    view3.frame               = CGRectMake(45, view2.y + 30, kSCREEN_WIDTH - 90, 30);
    view3.backgroundColor     = WELLGOCOLORWHITE;
    view3.alpha               = 0.07;
    view3.layer.cornerRadius  = 18;
    view3.layer.masksToBounds = YES;
    [self.view addSubview:view3];
    
    UIView *view4 = [[UIView alloc] init];
    view4.frame               = CGRectMake(45, view3.y + 30, kSCREEN_WIDTH - 90, 30);
    view4.backgroundColor     = WELLGOCOLORWHITE;
    view4.layer.cornerRadius  = 18;
    view4.alpha               = 0.07;
    view4.layer.masksToBounds = YES;
    [self.view addSubview:view4];
    
    UIView *view6 = [[UIView alloc] init];
    view6.frame               = CGRectMake(45,kSCREEN_HEIGHT - naView.bottom +heightIp4, kSCREEN_WIDTH - 90, 35);
    view6.backgroundColor     = WELLGOCOLORBLACK;
    view6.layer.cornerRadius  = 5;
    view6.layer.masksToBounds = YES;
    [self.view addSubview:view6];
    
    _loginButton                     = [[UIButton alloc] init];
    _loginButton.frame               = CGRectMake(45, view6.top+heightIp4, kSCREEN_WIDTH - 90, 35);
    [_loginButton setTitle:SN_Text(@"注册") forState:UIControlStateNormal];
    [_loginButton setTitleColor:SNCOLORWHITE forState:UIControlStateNormal];
    [_loginButton setTitleColor:SNCOLORGRAY forState:UIControlStateHighlighted];
    [_loginButton.titleLabel setFont:HHHFONTSIZE];
    [_loginButton setFontSize:17.0];
    [_loginButton addTarget:self action:@selector(loginButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_loginButton setTitleColorNormal:SNCOLORWHITE];
    [self.view addSubview:_loginButton];
    
    _textFiled1       = [[UITextField alloc] init];
    _textFiled1.frame = CGRectMake(_areaButton.origin.x + 40, _areaButton.origin.y +10, view1.width - 20, 25);
    [_textFiled1 changePlaceholder:SN_Text(@"请输入邮箱") withColor:HHHFONTCOLOR withFont:14.0+fontSize];
    _areaButton.hidden = YES;
    _textFiled1.textColor = WELLGOCOLORBLACK;
    _textFiled1.delegate  = self;
    [self.view addSubview:_textFiled1];
    
    _textFiled2              = [[UITextField alloc] init];
    _textFiled2.frame        = CGRectMake(_areaButton.origin.x + 38, _areaButton.origin.y +10 + 45 , view1.width - 20, 25);
    [_textFiled2 changePlaceholder:SN_Text(@"请再次输入邮箱") withColor:HHHFONTCOLOR withFont:14.0+fontSize];
    _textFiled2.textColor = WELLGOCOLORBLACK;
    _textFiled2.delegate  = self;
    [self.view addSubview:_textFiled2];
    
    _textFiled3       = [[UITextField alloc] init];
    _textFiled3.frame = CGRectMake(_areaButton.origin.x + 38, _areaButton.origin.y +10 + 90, view1.width - 20, 25);
    [_textFiled3 changePlaceholder:SN_Text(@"请输入密码") withColor:HHHFONTCOLOR withFont:14.0+fontSize];
    _textFiled3.textColor = WELLGOCOLORBLACK;
    _textFiled3.delegate  = self;
    [self.view addSubview:_textFiled3];
    _textFiled3.secureTextEntry = YES;
    
    _textFiled4       = [[UITextField alloc] init];
    _textFiled4.frame = CGRectMake(_areaButton.origin.x + 38, _areaButton.origin.y +10 + 135, view1.width - 20, 25);
    [_textFiled4 changePlaceholder:SN_Text(@"请再次输入密码") withColor:HHHFONTCOLOR withFont:14.0+fontSize];
    _textFiled4.textColor = WELLGOCOLORBLACK;
    _textFiled4.delegate  = self;
    [self.view addSubview:_textFiled4];
    _textFiled4.secureTextEntry = YES;
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = SNCOLORGRAY;
    line1.alpha           = 0.33;
    line1.frame           = CGRectMake(_textFiled1.origin.x -5, _textFiled1.origin.y + _textFiled1.height + 5, _textFiled1.width +10, 1);
    [self.view addSubview:line1];
    
    UIView *line2 = [[UIView alloc] init];
    line2.backgroundColor = SNCOLORGRAY;
    line2.alpha           = 0.33;
    line2.frame           = CGRectMake(_textFiled2.origin.x -5, _textFiled2.origin.y + _textFiled2.height + 5, _textFiled2.width +10, 1);
    [self.view addSubview:line2];
    
    UIView *line3 = [[UIView alloc] init];
    line3.backgroundColor = SNCOLORGRAY;
    line3.alpha           = 0.33;
    line3.frame           = CGRectMake(_textFiled3.origin.x -5, _textFiled3.origin.y + _textFiled3.height + 5, _textFiled3.width +10, 1);
    [self.view addSubview:line3];
    
    UIView *line4 = [[UIView alloc] init];
    line4.backgroundColor = SNCOLORGRAY;
    line4.alpha           = 0.33;
    line4.frame           = CGRectMake(_textFiled4.origin.x -5, _textFiled4.origin.y + _textFiled4.height + 5, _textFiled4.width +10, 1);
    [self.view addSubview:line4];
    
    UILabel *infoLabel1 = [[UILabel alloc] initWithFrame:SNFRAME(45, naView.bottom, screenWidth - 45, 35)];
    infoLabel1.textColor = SNCOLORBLACK;
    infoLabel1.font = SNFONT(16.0+fontSize);
    infoLabel1.text = SN_Text(@"1:填写邮箱与密码");
    [self.view addSubview:infoLabel1];
    
    UILabel *infoLabel2 = [[UILabel alloc] initWithFrame:SNFRAME(45, line4.bottom + 12+heightSize, screenWidth - 45, 35)];
    infoLabel2.textColor = SNCOLORBLACK;
    infoLabel2.font = SNFONT(16.0+fontSize);
    infoLabel2.text = SN_Text(@"2:输入密保问题");
    [self.view addSubview:infoLabel2];
    
    UILabel *infoLabel3 = [[UILabel alloc] initWithFrame:SNFRAME(50, infoLabel2.bottom +10 +heightSize +heightIp4, 70, 35)];
    infoLabel3.textColor = SNCOLORBLACK;
    infoLabel3.font = SNFONT(13.0+fontSize);
    infoLabel3.text = SN_Text(@"问题1");
    [self.view addSubview:infoLabel3];

    _requestTextFiled1       = [[UITextField alloc] init];
    _requestTextFiled1 .frame = CGRectMake(infoLabel3.left + 10, infoLabel3.bottom + 10 +heightSize +heightIp4, view1.width - 30, 25);
    [_requestTextFiled1  changePlaceholder:SN_Text(@"请输入答案1") withColor:HHHFONTCOLOR withFont:13.0+fontSize];
    _requestTextFiled1 .textColor = WELLGOCOLORBLACK;
    _requestTextFiled1 .delegate  = self;
    [self.view addSubview:_requestTextFiled1];
    
    UIView *requestLine1 = [[UIView alloc] initWithFrame:SNFRAME(_requestTextFiled1.left-10, _requestTextFiled1.bottom, _requestTextFiled1.width + 25, 1)];
    requestLine1.backgroundColor = SNCOLORGRAY;
    requestLine1.alpha           = 0.33;
    [self.view addSubview:requestLine1];
    
    UILabel *infoLabel4 = [[UILabel alloc] initWithFrame:SNFRAME(50, requestLine1.bottom + 20 +heightSize +heightIp4, 70, 35)];
    infoLabel4.textColor = SNCOLORBLACK;
    infoLabel4.font = SNFONT(13.0+fontSize);
    infoLabel4.text = SN_Text(@"问题2");
    [self.view addSubview:infoLabel4];
    
    _requestTextFiled2       = [[UITextField alloc] init];
    _requestTextFiled2 .frame = CGRectMake(infoLabel4.left + 10, infoLabel4.bottom + 10+heightSize+heightIp4, view1.width - 30, 25);
    [_requestTextFiled2  changePlaceholder:SN_Text(@"请输入答案2") withColor:HHHFONTCOLOR withFont:13.0+fontSize];
    _requestTextFiled2 .textColor = WELLGOCOLORBLACK;
    _requestTextFiled2 .delegate  = self;
    [self.view addSubview:_requestTextFiled2];
    
    UIView *requestLine2 = [[UIView alloc] initWithFrame:SNFRAME(_requestTextFiled2.left -10, _requestTextFiled2.bottom, _requestTextFiled2.width + 25, 1)];
    requestLine2.backgroundColor = SNCOLORGRAY;
    requestLine2.alpha           = 0.33;
    [self.view addSubview:requestLine2];
    
    _requestSelect1 = [[UILabel alloc] initWithFrame:SNFRAME(infoLabel3.right, requestLine1.bottom -45 - 30 -2, screenWidth - infoLabel3.right - 60, 45)];
    _requestSelect1.textColor = SNCOLORBLACK;
    _requestSelect1.font = SNSFONT(11.0+fontSize);
    _requestSelect1.text = SN_Text(@"密保1");
    _requestSelect1.numberOfLines = 3;
    _requestSelect1.adjustsFontSizeToFitWidth = YES;
    _requestSelect1.centerY = infoLabel3.centerY;
    [self.view addSubview:_requestSelect1];
    
    _requestSelect2 = [[UILabel alloc] initWithFrame:SNFRAME(infoLabel3.right, requestLine2.bottom -45 - 30 -2, screenWidth - infoLabel3.right - 60, 45)];
    _requestSelect2.textColor = SNCOLORBLACK;
    _requestSelect2.font = SNSFONT(11.5+fontSize);
    _requestSelect2.text = SN_Text(@"密保4");
    _requestSelect2.numberOfLines = 3;
    _requestSelect2.adjustsFontSizeToFitWidth = YES;
    _requestSelect2.centerY = infoLabel4.centerY;
    [self.view addSubview:_requestSelect2];
    
    UIView *request1 = [[UIView alloc] initWithFrame:SNFRAME(_requestSelect1.left -5, _requestSelect1.top, _requestSelect1.width + 15, 45)];
    request1.alpha           = 0.33;
    [self.view addSubview:request1];
    request1.layer.borderWidth = 1;
    request1.layer.borderColor = SNCOLORGRAY.CGColor;
    
    UIView *request2 = [[UIView alloc] initWithFrame:SNFRAME(_requestSelect2.left -5, _requestSelect2.top, _requestSelect2.width + 15, 45)];
    request2.alpha           = 0.33;
    [self.view addSubview:request2];
    request2.layer.borderWidth = 1;
    request2.layer.borderColor = SNCOLORGRAY.CGColor;
    
    UIButton *button01 = [[UIButton alloc] init];
    button01.frame = SNFRAME(request1.right - 25, request1.top +5, 30, 30);
    [button01 setImage:[UIImage image:@"注册问题下拉"] forState:UIControlStateNormal];
    button01.tag = 1;
    [self.view addSubview:button01];
    
    UIButton *button02 = [[UIButton alloc] init];
    button02.frame = SNFRAME(request2.right - 25, request2.top +5, 30, 30);
    [button02 setImage:[UIImage image:@"注册问题下拉"] forState:UIControlStateNormal];
    button02.tag = 2;
    [self.view addSubview:button02];
    [button01 addTarget:self action:@selector(buttonClickSender:) forControlEvents:UIControlEventTouchUpInside];
    [button02 addTarget:self action:@selector(buttonClickSender:) forControlEvents:UIControlEventTouchUpInside];
    _select1 = 0;
    _select2 = 0;
}

- (void)buttonClickSender:(UIButton *)sender
{
    SHESelectTable *sTable;
    if (sender.tag ==1) {
        NSArray *seleArray=@[SN_Text(@"密保1"),SN_Text(@"密保2"),SN_Text(@"密保3")];
        //获取某个控件在屏幕上的位置
        sTable=[[SHESelectTable alloc]initWithFrame:CGRectMake(0, 0, KSW, KSH) withTableFrame:CGRectMake(_requestSelect1.left, _requestSelect1.bottom, _requestSelect1.width, 40*seleArray.count) withDataArray:seleArray withSelectindex:_select1];
        sTable.selTable.frame=CGRectMake(_requestSelect1.left-3, _requestSelect1.bottom, _requestSelect1.width+15, 40*seleArray.count);
        sTable.tag = 1;
    }
    else
    {
        NSArray *seleArray;
        if (KK_ShareData.ip4) {
        seleArray=@[SN_Text(@"密保4"),SN_Text(@"密保5")];
        }
        else
        {
        seleArray=@[SN_Text(@"密保4"),SN_Text(@"密保5"),SN_Text(@"密保6")];
        }

        //获取某个控件在屏幕上的位置
        sTable=[[SHESelectTable alloc]initWithFrame:CGRectMake(0, 0, KSW, KSH) withTableFrame:CGRectMake(_requestSelect2.left, _requestSelect2.bottom, _requestSelect2.width, 40*seleArray.count) withDataArray:seleArray withSelectindex:_select2];
        sTable.selTable.frame=CGRectMake(_requestSelect2.left-3, _requestSelect2.bottom, _requestSelect2.width+15, 40*seleArray.count);
        sTable.tag = 2;
    }
    if (sTable.tag == 1) {
        sTable.returnBlock=^(NSString *cityString)
        {
            if ([cityString isEqualToString:SN_Text(@"密保1")]) {
                _select1 = 0;
            }
            if ([cityString isEqualToString:SN_Text(@"密保2")]) {
                _select1 = 1;
            }
            if ([cityString isEqualToString:SN_Text(@"密保3")]) {
                _select1 = 2;
            }
            _requestSelect1.text = cityString;
        };
    }
    else
    {
        sTable.returnBlock=^(NSString *cityString)
        {
            if ([cityString isEqualToString:SN_Text(@"密保4")]) {
                _select2 = 0;
            }
            if ([cityString isEqualToString:SN_Text(@"密保5")]) {
                _select2 = 1;
            }
            if ([cityString isEqualToString:SN_Text(@"密保6")]) {
                _select2 = 2;
            }
            _requestSelect2.text = cityString;
        };
    }

    [[UIApplication sharedApplication].keyWindow addSubview:sTable];
    [UIView animateWithDuration:0.2 animations:^{
        
        sTable.selTable.alpha=1;
    }];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [_textFiled1 resignFirstResponder];
    [_textFiled2 resignFirstResponder];
    [_textFiled3 resignFirstResponder];
    [_textFiled4 resignFirstResponder];
    return YES;
}

// 注册按钮
- (void)loginButtonClick:(UIButton *)sender {
    [_loginButton setTitleColorNormal:HHHFONTCOLOR];
    [self performSelector:@selector(delayLoginButtonReset) withObject:nil afterDelay:0.1];
    NSLog(@"注册ButtonClick>>>>>");
    [self emailRegistration:sender]; // 邮箱注册
    // 成功之后进入用户信息
}

- (void)delayLoginButtonReset {
    [_loginButton setTitleColorNormal:WELLGOCOLORWHITE];
}

// 注册接口
- (void)registration {
    if (_textFiled1.text.length <= 0 || _textFiled2.text.length <= 0|| _textFiled2.text.length <= 0 || _textFiled4.text.length <= 0) {
        SHOWMBProgressHUD(nil,SN_Text(@"信息请填写完整"), nil, NO, 2.0);
        return;
    }
    if (![_textFiled3.text isPassword]) {
       SHOWMBProgressHUD(nil,SN_Text( @"密码必须为6～14位的数字或字母"),nil, NO, 2.0);
        return;
    }
    if (![_textFiled1.text isEqualToString:_textFiled2.text]) {
        SHOWMBProgressHUD(nil, SN_Text(@"您输入的两个邮箱不匹配"), nil, NO, 2);
        return;
    }
    if (![_textFiled4.text isEqualToString:_textFiled3.text]) {
        SHOWMBProgressHUD(nil,SN_Text(@"您输入的两个密码不匹配。"), nil, NO, 2);
        return;
    }
    
    [LOGINACCOUNT setObjectValue:_textFiled1.text];
    [LOGINPASSWORD setObjectValue:_textFiled3.text];
    [LOGINCODE setObjectValue:_textFiled2.text];
    [LOGINAREA setObjectValue:_areaButton.titleLabel.text];
    DEF_WEAKSELF_(RegistrationViewController)
    [SN_Net RegistratWithPhonesuccess:^(id object) {
        UserInfoModel *model = object;
        [KK_LastUser setObjectValue:model.user_id];
        [SN_PublicClass updateUser];
        SN_USER.loginAccount = _textFiled1.text;
        SN_USER.loginPassword = _textFiled3.text;
        SN_USER.is_first = model.is_first;
        SN_USER.user_id = model.user_id;
        SN_USER.access_token = model.access_token;
        SN_USER.registerDate = [NSDate date];
        [SN_USER updateToDB];
        
        if (model.is_first == 1) {
            NSLog(@"设置个人信息界面>>>>>");
        } else {
            NSLog(@"进入主页 并获取用户信息>>>>");
        }
        [weakSelf backClick];
    } fail:^(id object) {
    }];
}

// 邮箱注册接口
- (void)emailRegistration:(UIButton *)sender {
    if (_textFiled1.text.length <= 0 || _textFiled2.text.length <= 0 || _textFiled3.text.length <= 0|| _textFiled4.text.length <= 0) {
        SHOWMBProgressHUD(nil, SN_Text(@"信息请填写完整"), nil, NO, 2.0);
        return;
    }
    if (![self isValidateEmail:_textFiled1.text] || ![self isValidateEmail:_textFiled2.text]) {
        SHOWMBProgressHUD(nil,SN_Text(@"邮件格式不正确"), nil, NO, 2.0);
        return;
    }
    if (![_textFiled3.text isPassword]||![_textFiled4.text isPassword]) {
       SHOWMBProgressHUD(nil,SN_Text( @"密码必须为6～14位的数字或字母"),nil, NO, 2.0);
        return;
    }
    if (![_textFiled1.text isEqualToString:_textFiled2.text]) {
        SHOWMBProgressHUD(nil, SN_Text(@"您输入的两个邮箱不匹配"), nil, NO, 2);
        return;
    }
    if (![_textFiled4.text isEqualToString:_textFiled3.text]) {
        SHOWMBProgressHUD(nil, SN_Text(@"您输入的两个密码不匹配。"), nil, NO, 2);
        return;
    }
    
    if (_requestTextFiled1.text.length <=0 || _requestTextFiled2.text.length <=0) {
        SHOWMBProgressHUD(nil, SN_Text(@"请填写问题答案"), nil, NO, 2.0);
        return;
    }
    
    
    [LOGINACCOUNT setObjectValue:_textFiled1.text];
    [LOGINPASSWORD setObjectValue:_textFiled3.text];
    
    NSDictionary *dic1    = @{
                              @"question":StrByInt(_select1+1), @"answer":_requestTextFiled1.text,
                              };
    NSDictionary *dic2    = @{
                              @"question":StrByInt(_select2+4), @"answer":_requestTextFiled2.text,
                              };
    NSArray *result = [NSArray arrayWithObjects:dic1,dic2, nil];
    
    [LOGINCODE setObjectValue:result];
     SHOWMBProgressHUDIndeterminate(SN_Text(@"请等待..."), nil, @"登录中");
    [SN_Net RegistratWithEmailsuccess:^(id object)
     {
            HIDDENMBProgressHUD;
         if (object[@"ret"] && [object[@"ret"] intValue] == 0) {
             NSDictionary *dic = [object objectForKey:@"data"];
             UserInfoModel *model = [UserInfoModel parseString:dic.YYJSONString];
             [KK_LastUser setObjectValue:model.user_id];
             [SN_PublicClass updateUser];
             SN_USER.loginAccount = _textFiled1.text;
             SN_USER.loginPassword = _textFiled3.text;
             SN_USER.is_first = model.is_first;
             SN_USER.user_id = model.user_id;
             SN_USER.access_token = model.access_token;
             SN_USER.portrait = model.portrait;
             [SN_USER updateToDB];
             sender.enabled = YES;
             
             [SN_Net downImageHeardWith];
             [kK_App enterLoginVc];
         } else {
           
         }
     }                           fail:^(id object) {
             HIDDENMBProgressHUD;
     }];
        [self performSelector:@selector(loginOnTimeOut) withObject:nil afterDelay:30.0];
}

- (void)loginOnTimeOut
{
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(loginOnTimeOut) object:nil];
     HIDDENMBProgressHUD;
}

- (void)dealloc
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(loginOnTimeOut) object:nil];
}

- (void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL)isValidateEmail:(NSString *)email {
    NSString    *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest  = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

